<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	
    public function index(){
        $this->display();
    }
	
	/*验证码方法*/
	public function yzm(){
		$config =    array(
		'fontSize'    =>    30,    // 验证码字体大小
		'length'      =>    4,     // 验证码位数
		'useNoise'    =>    false, // 验证码杂点
		);
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	
	/*检查验证码是否正确*/
	public function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}
	
	public function add(){
		$user = D('User');
		$data = $user->create();
		//$data['nickname'] = I('nickname'); 
		//$data['password'] = I('password');
		//dump($data);die;
		if (!$this->check_verify(I('post.yzm'))) {
            $this->error('验证码错误');
        }
		$res = $user->add($data);
		if($res){
			$this->success('账号注册成功');
		}else{
			$this->error($user->getError());
		}
	}
}